#pragma once

#include "ReclassifyObjectAction.h"

#include "Classifier.h"
#include "InputPin.h"

namespace uml {

const bool ReclassifyObjectAction::isReplaceAll_default_ = false;
ReclassifyObjectAction::ReclassifyObjectAction(const QString& umlType)
    : Action(umlType) {}

void ReclassifyObjectAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    isReplaceAll_ = json.value("isReplaceAll").toBool(isReplaceAll_default_);
    JsonSerializable::fromJsonArray(newClassifiers_, "newClassifiers", json, errorList);
    object_ = JsonSerializable::create<InputPin>(json.value("object"), errorList);

    JsonSerializable::fromJsonArray(oldClassifiers_, "oldClassifiers", json, errorList);
}

void ReclassifyObjectAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (isReplaceAll_ != isReplaceAll_default_) {
        json.insert("isReplaceAll", isReplaceAll_);
    }
    JsonSerializable::toJsonArray(newClassifiers_, "newClassifiers", json);
    if (object_) {
        QJsonObject object_json;
        object_->toJson(object_json);
        json.insert("object", object_json);
    }
    JsonSerializable::toJsonArray(oldClassifiers_, "oldClassifiers", json);
}

/// <summary>
/// isReplaceAll getter
/// Specifies whether existing Classifiers should be removed before adding the new
/// Classifiers.
/// </summary>
bool ReclassifyObjectAction::isReplaceAll() const {
    return isReplaceAll_;
}

/// <summary>
/// isReplaceAll setter
/// Specifies whether existing Classifiers should be removed before adding the new
/// Classifiers.
/// </summary>
void ReclassifyObjectAction::setIsReplaceAll(bool value) {
    isReplaceAll_ = value;
}

/// <summary>
/// newClassifiers getter
/// A set of Classifiers to be added to the Classifiers of the given object.
/// </summary>
vector<shared_ptr<Classifier>>& ReclassifyObjectAction::newClassifiers() {
    return newClassifiers_;
}

/// <summary>
/// object getter
/// The InputPin that holds the object to be reclassified.
/// </summary>
shared_ptr<InputPin> ReclassifyObjectAction::object() const {
    return object_;
}

/// <summary>
/// object setter
/// The InputPin that holds the object to be reclassified.
/// </summary>
void ReclassifyObjectAction::setObject(shared_ptr<InputPin> value) {
    object_ = value;
}

/// <summary>
/// oldClassifiers getter
/// A set of Classifiers to be removed from the Classifiers of the given object.
/// </summary>
vector<shared_ptr<Classifier>>& ReclassifyObjectAction::oldClassifiers() {
    return oldClassifiers_;
}

} // namespace uml
